Skip to content

feat(workspace-server): import & store Claude Code CLI sessions#2877

Merged
adboio merged 1 commit into
mainfrom
posthog-code/import-cc-2-backend
Jun 26, 2026
Merged

feat(workspace-server): import & store Claude Code CLI sessions#2877
adboio merged 1 commit into
mainfrom
posthog-code/import-cc-2-backend

Conversation

@adboio

@adboio adboio commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Problem

#2876 enables replaying cli sessions; need a way to discover + import them

Changes

enables claude code cli session discovery + import

still not user-accessible, UX will come in the next PR up

How did you test this?

manually (upstack)

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

adboio commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit f15ae36.

@greptile-apps

greptile-apps Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Comments Outside Diff (2)

  1. packages/workspace-server/src/services/claude-cli-sessions/claude-cli-sessions.ts, line 2177-2182 (link)

    P2 Files deleted before the DB row is cleared

    removeSnapshotFiles runs first, then deleteByTaskId. If anything interrupts execution between those two steps (process crash, unexpected exception after force: true actually succeeds), the import row survives while its files are gone. On the next listForRepo call the source session shows "imported" with a now-deleted importedTaskId, and there is no way to re-import without manually clearing the DB.

    Reversing the order — delete the DB row first, then the files — produces better failure semantics: if the file deletion subsequently fails, the source session already shows "new" and can be re-imported; any orphaned file wastes only disk space.

  2. packages/workspace-server/src/services/claude-cli-sessions/claude-cli-sessions.ts, line 2099 (link)

    P2 Full-file read in importSession vs chunked reads in the listing path

    fs.readFile(sourcePath, "utf-8") loads the entire transcript into a JavaScript string before any processing, while listForRepo deliberately uses bounded head/tail reads. A CLI session with thousands of turns can easily be several megabytes; this import call then allocates a second copy while building the rewritten array. Using readline (or createReadStream) would keep memory usage proportional to a single line at a time and is consistent with the chunked approach already used in scanning.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Reviews (1): Last reviewed commit: "feat(workspace-server): import & store C..." | Re-trigger Greptile

@adboio adboio force-pushed the posthog-code/import-cc-2-backend branch from 8cbec5f to b944070 Compare June 24, 2026 15:20
@adboio adboio force-pushed the posthog-code/import-cc-1-agent-replay branch from 442269e to 153d55c Compare June 24, 2026 15:20
@adboio adboio force-pushed the posthog-code/import-cc-2-backend branch from b944070 to e9a736c Compare June 24, 2026 15:40
@adboio adboio requested a review from a team June 24, 2026 15:44
@adboio adboio force-pushed the posthog-code/import-cc-2-backend branch from e9a736c to 0253564 Compare June 24, 2026 16:16
@adboio adboio marked this pull request as ready for review June 24, 2026 16:17
@greptile-apps

greptile-apps Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Reviews (2): Last reviewed commit: "feat(workspace-server): import & store C..." | Re-trigger Greptile

@adboio adboio mentioned this pull request Jun 25, 2026
2 tasks

adboio commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

Merge activity

  • Jun 26, 2:31 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jun 26, 2:32 PM UTC: Graphite couldn't merge this PR because it had merge conflicts.
  • Jun 26, 2:57 PM UTC: @adboio merged this pull request with Graphite.

@adboio adboio changed the base branch from posthog-code/import-cc-1-agent-replay to graphite-base/2877 June 26, 2026 14:31
@adboio adboio changed the base branch from graphite-base/2877 to main June 26, 2026 14:31
@adboio adboio force-pushed the posthog-code/import-cc-2-backend branch from 0253564 to fa1ccb0 Compare June 26, 2026 14:42
Add the server side of importing a Claude Code CLI session: a
claude_session_imports table + repository, the claude-cli-sessions
service (scan ~/.claude for a repo, snapshot a transcript into
CLAUDE_CONFIG_DIR, and track imports with content-fingerprint
divergence detection), agent loadSession support to resume the imported
session, best-effort snapshot cleanup on task delete, and the tRPC
router + DI wiring.

Part 2/3 of splitting #2873 (import Claude Code sessions).

Generated-By: PostHog Code
Task-Id: 6c93b6e8-27b6-45c8-8135-73a09076ea93
@adboio adboio force-pushed the posthog-code/import-cc-2-backend branch from fa1ccb0 to f15ae36 Compare June 26, 2026 14:43
@adboio adboio merged commit 4089bea into main Jun 26, 2026
24 checks passed
@adboio adboio deleted the posthog-code/import-cc-2-backend branch June 26, 2026 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants